package mylab.commons.web.mvc.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import mylab.base.model.dto.Result;
import mylab.base.model.entity.Entity;
import mylab.starters.mybatis.template.SuperService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.io.Serializable;
import java.util.Arrays;

/**
 * controller~删除
 *
 * @param <K> 对应的entity的ID
 * @param <E> 对应的entity
 * @param <S> 对应的service
 */
public interface RemoveController<
        K extends Serializable,
        E extends Entity<K>,
        S extends SuperService<K, E>>
        extends BaseController<K, E, S> {

    @ApiOperation(value = "删除一条")
    @ApiOperationSupport(order = 31)
    @DeleteMapping("/remove/{id}")
    default Result<Boolean> removeById(@PathVariable("id") K id) {
        return Result.newSuccess(getService().removeById(id));
    }

    @ApiOperation(value = "批量删除")
    @ApiOperationSupport(order = 32)
    @DeleteMapping("/remove/batch/{ids}")
    default Result<Boolean> removeByIds(@PathVariable("ids") K[] ids) {
        return Result.newSuccess(getService().removeByIds(Arrays.asList(ids)));
    }
}
